package com.bsc.rtc.lib.libraries.RecycleViewBase;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Rect;
import android.os.Bundle;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.Scroller;
import android.widget.TextView;

import com.bsc.rtc.lib.libraries.R;
import com.bsc.rtc.lib.libraries.RecycleViewBase.base.ItemTouchHelperCallBack;
import com.bsc.rtc.lib.libraries.RecycleViewBase.base.ViewHolder;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class RecyclerDemoActivity extends AppCompatActivity {
    @BindView(R.id.mRecycle)
    public RecyclerView recyclerView;
    CommonAdapter adapter;

    ItemTouchHelper itemTouchHelper;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recycler_demo);
        ButterKnife.bind(this);
        initView();
    }


    private void initView() {
        List<String> list = new ArrayList<String>();
        for (int i = 0; i < 100; i++) {
            list.add("s" + i);
        }
        //recyclerView.setLayoutManager(new StaggeredGridLayoutManager(3,StaggeredGridLayoutManager.VERTICAL));
        recyclerView.setLayoutManager(new GridLayoutManager(this,3));
        adapter = new CommonAdapter(this, R.layout.item_ry_layout, list) {

            @Override
            protected void convert(ViewHolder holder, Object o, int position) {
                holder.setText(R.id.item, list.get(position));
                holder.setOnClickListener(R.id.tv_srolll1, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Log.i("zzw","position="+position);
                        Log.i("zzw","LayoutPosition="+ holder.getLayoutPosition());
                        list.remove(position);
                        adapter.notifyItemRemoved(holder.getLayoutPosition());
                    }
                });
            }
        };

        recyclerView.setAdapter(adapter);
        itemTouchHelper = new ItemTouchHelper(new ItemTouchHelperCallBack<String>(list, adapter, new ItemTouchHelperCallBack.DeleteCallBack() {
            @Override
            public boolean delete(int position) {
                Log.i("zzw", "position=" + position);
          /*      list.remove(position);
                adapter.notifyItemRemoved(position);*/
                adapter.notifyDataSetChanged();
                return false;
            }
        }));
        itemTouchHelper.attachToRecyclerView(recyclerView);

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

    }
}
